#include "RsGisLibClbLandtoRadiMultiAdd.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibClbLandtoRadiMultiAdd::RsGisLibClbLandtoRadiMultiAdd(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibClbLandtoRadiMultiAdd();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_LandtoRadiMultiAdd, SIGNAL(clicked()), this, SLOT(on_action_Button_LandtoRadiMultiAdd_clicked()));

	ui->textBrowser_ParameterDescription->setText(
		"Band Num - Index of Band Num from 1\nAdd Value - RADIANCE_ADD from Landsat header\nMulti Value - RADIANCE_MULT from Landsat header\nOutput Band Name - Name of output band\nGdal Format - string specifying the output image format"
	);

	ui->textBrowser_ParameterDescription->setEnabled(false);

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\LT51200352005057BJC01.tif");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestLandtoRadiMultiAdd.tif");
	ui->lineEdit_BandNum->setText("1");
	ui->lineEdit_AddValue->setText("-2.28583");
	ui->lineEdit_MultiValue->setText("0.766");
	ui->lineEdit_OutBandName->setText("LandtoRadiBand1");
	ui->lineEdit_GdalFormat->setText("GTIFF");

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibClbLandtoRadiMultiAdd::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibClbLandtoRadiMultiAdd::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibClbLandtoRadiMultiAdd::on_action_Button_LandtoRadiMultiAdd_clicked()
{
	{
		if (ui->lineEdit_InputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Input File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Output File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_BandNum->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Band Num is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_AddValue->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Add Value is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_MultiValue->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Multi Value is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutBandName->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Out Band Name is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Priority->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Priority is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}
	}

	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("imageCalibration"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("LandtoRadiMultiAdd"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(int(ui->lineEdit_BandNum->text().toInt()));
	AlgParaList << QVariant(double(ui->lineEdit_AddValue->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_MultiValue->text().toDouble()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutBandName->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}
